package com.example.asus.yuejian_10.adapter;

import android.content.Context;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.asus.yuejian_10.R;
import com.example.asus.yuejian_10.activity.ClubActivity;
import com.example.asus.yuejian_10.bean.ClubList;
import com.squareup.picasso.Picasso;
import java.util.List;


import static com.example.asus.yuejian_10.Config.PIC_URL;
import static com.example.asus.yuejian_10.base.BaseActivity.clubid;

/**
 * Created by Wolfh on 2017/5/19.
 */

public class ClublistAdapter extends BaseListAdapter {

    public ClublistAdapter(Context context, List list) {
        super(context, list);
    }

    @Override
    protected RecyclerView.ViewHolder onCreateVH(ViewGroup parent, LayoutInflater layoutInflater, int viewType) {
        View ItemView = layoutInflater.inflate(R.layout.item_club,parent,false);

        ClubViewHolder viewHolder = new ClubViewHolder(ItemView);//定义显示部件

        return viewHolder;
    }

    @Override
    protected void onBindVH(RecyclerView.ViewHolder holder, int position, List data) {
        final ClubList clublist = (ClubList) data.get(position);
        if(holder instanceof  ClubViewHolder){

            ClubViewHolder viewHolder = (ClubViewHolder) holder;
            viewHolder.name.setText(clublist.getClub_name());
            if(!clublist.getThumb().equals("")){
                Picasso.with(context)
                        .load(PIC_URL+clublist.getThumb())
                        .into(viewHolder.pic);
            }
            else {
                viewHolder.pic.setImageResource(R.drawable.diagonallayout_background);
            }

            clubid = clublist.getId();


            viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent = new Intent(context, ClubActivity.class);
                    intent.putExtra("club",clublist);

                    context.startActivity(intent);
                }

            });

        }

    }
}
